﻿using Microsoft.Extensions.DependencyInjection;

namespace GetSmartIDEList.Lib.AOP
{
    /// <summary>
    /// IServiceProviderFactory  实现  IServiceProviderFactory<ContainerBuilder>
    /// 
    /// ContainerBuilder--->IServiceProvider
    /// 欠缺工厂注册-实例注册-泛型处理等
    /// </summary>
    public class ContainerFactory : IServiceProviderFactory<ContainerBuilder>
    {
        /// <summary>
        /// 获取ContainerBuilder
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public ContainerBuilder CreateBuilder(IServiceCollection services)
        {
            return new ContainerBuilder(services);//给ContainerBuilder提供的是IServiceCollection
        }
        /// <summary>
        /// 创建容器的实例，最终就是这个实例为准，全局使用
        /// 我只有个ContainerBuilder的参数，那么创建IServiceProvider的职责就交给你了
        /// </summary>
        /// <param name="containerBuilder"></param>
        /// <returns></returns>
        public IServiceProvider CreateServiceProvider(ContainerBuilder containerBuilder)
        {
            return containerBuilder.GetServiceProvider();
        }
    }
}
